﻿/*
 * 由SharpDevelop创建。
 * 用户： xieen
 * 日期: 2013-08-21
 * 时间: 15:01
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections.Generic;

namespace GoF23Learning._19.Interpreter_Pattern.Refactor
{
	/// <summary>
	/// Description of TenThousand.
	/// </summary>
	public class TenThousandExpression:Expression
	{
		
		public override int Multiplier()
		{
			 return  10000;
		}
		
		public override string GetPostfix()
		{
			 return "万";
		}
		
		public override int GetLength()
		{
			 return 5;
		}
		
		
		public override void Interpreter(Context context)
		{ 
			int length = context.Statement.Length;
			if( length==0)
				return ;
			
			List<Expression> tree = new List<Expression>();
			tree.Add(new BitsExpression());
			tree.Add(new TenExpression());
			tree.Add(new HundredExpression());

			var suffix = this.GetPostfix();
			//乘数
			var multiplier= this.Multiplier();
			foreach (string key in dic.Keys) {
				
				if(context.Statement.EndsWith(suffix))
				{
				   	int temp = context.Data;
				   	context.Data = 0;
				   	foreach (var exp in tree) {
				   		exp.Interpreter(context);
					}
				   	context.Data = temp + multiplier*context.Data;
				}			 
				
			}
		}
	}
}
